/*
 * ===========================================================================================
 * = COPYRIGHT
 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
 *   This software is supplied under the terms of a license agreement or nondisclosure
 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
 *   disclosed except in accordance with the terms in that agreement.
 *     Copyright (C) 2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
 * ===========================================================================================
 */

import 'package:flutter/material.dart';
import 'package:pos_link/auto_data_source/auto_data_source_common.dart';
import 'package:pos_link/auto_data_source/auto_report_request_data_source.dart';
import 'package:pos_link/auto_data_source/auto_report_response_data_source.dart';
import 'package:pos_link/auto_pigeon/poslink_sdk_report.dart';
import 'package:pos_link/model/response_db.dart';
import 'comm_setting_view_model.dart';

class ReportViewModel extends ChangeNotifier {
  Future startReport(ResponseDataBase responseDataBase, List<Map> dataSource) async {
    POSLinkReportApi ReportApi = POSLinkReportApi();

    /// command
    Map cmdData = dataSource.first;
    switch (cmdData[kValue]) {
      case ReportCommand.HostDetailReportRequest:
        ReportHostDetailReportRequest req = ReportReqData.formHostDetailReportRequest(dataSource);
        ReportHostDetailReportResponse rsp = await ReportApi.hostDetailReport(req);
        ReportRspData.parseRspReportHostDetailReportResponse(rsp, responseDataBase.reportData);
        break;
      case ReportCommand.LocalTotalReportRequest:
        ReportLocalTotalReportRequest req = ReportReqData.formLocalTotalReportRequest(dataSource);
        ReportLocalTotalReportResponse rsp = await ReportApi.localTotalReport(req);
        ReportRspData.parseRspReportLocalTotalReportResponse(rsp, responseDataBase.reportData);
        break;
      case ReportCommand.LocalDetailReportRequest:
        ReportLocalDetailReportRequest req = ReportReqData.formLocalDetailReportRequest(dataSource);
        ReportLocalDetailReportResponse rsp = await ReportApi.localDetailReport(req);
        ReportRspData.parseRspReportLocalDetailReportResponse(rsp, responseDataBase.reportData);
        break;
      case ReportCommand.SafSummaryReportRequest:
        ReportSafSummaryReportRequest req = ReportReqData.formSafSummaryReportRequest(dataSource);
        ReportSafSummaryReportResponse rsp = await ReportApi.safSummaryReport(req);
        ReportRspData.parseRspReportSafSummaryReportResponse(rsp, responseDataBase.reportData);
        break;
      case ReportCommand.LocalFailedReportRequest:
        ReportLocalFailedReportRequest req = ReportReqData.formLocalFailedReportRequest(dataSource);
        ReportLocalFailedReportResponse rsp = await ReportApi.localFailedReport(req);
        ReportRspData.parseRspReportLocalFailedReportResponse(rsp, responseDataBase.reportData);
        break;
      case ReportCommand.HistoryReportRequest:
        ReportHistoryReportRequest req = ReportReqData.formHistoryReportRequest(dataSource);
        ReportHistoryReportResponse rsp = await ReportApi.historyReport(req);
        ReportRspData.parseRspReportHistoryReportResponse(rsp, responseDataBase.reportData);
        break;
      case ReportCommand.HostReportRequest:
        ReportHostReportRequest req = ReportReqData.formHostReportRequest(dataSource);
        ReportHostReportResponse rsp = await ReportApi.hostReport(req);
        ReportRspData.parseRspReportHostReportResponse(rsp, responseDataBase.reportData);
        break;

      default:
        throw Exception('undefined function');
      //break;
    }
  }
}
